package logic;

import gui.AcademicFrame;
import gui.Dialog;

import java.awt.Desktop;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import com.itextpdf.text.DocumentException;
import common.ChatIF;

/**
 * Reports control
 */
public class ReportsControl implements ChatIF{

	public static void handelActivityReport(ArrayList<Object> res) {
	/**
	 * create activity report using PDFGenerator
	 */	
	 String from;
	 String to;
	 String num1;
	 String num2;
	 String num3;
	 String num4;
	 String num5;
	 double[] colData1;
	 double[] colData2;
	 double[] colData3;
	 double[] colData4;
	 double[] colData5;
	 ArrayList<Object> message= new ArrayList<Object>();
	    try {
	    	System.out.println("in handelActivityReport ");
	    	System.out.println("before calling to pdfgenerator ");
	    	from= res.get(2).toString();
	    	System.out.println(from);
	    	to= res.get(3).toString();
	    	num1= res.get(4).toString();
	    	num2= res.get(5).toString();
	    	num3= res.get(6).toString();
	    	num4= res.get(7).toString();
	    	num5= res.get(8).toString();
	    	System.out.println("after num5= res.get(8).toString();");
	    	colData1=(double[]) res.get(9);
	    	colData2=(double[]) res.get(10);
	    	colData3=(double[]) res.get(11);
	    	colData4=(double[]) res.get(12);
	    	colData5=(double[]) res.get(13);
	    	System.out.println("after median=(double[]) res.get(9);");
	    	System.out.println(from);
	    	
			PDFGenerator.createActivityReport("/", from, to, num1, num2, num3, num4, num5, colData1, colData2, colData3, colData4, colData5);
	    	}
	   /* } catch (DocumentException | IOException e) {
			// TODO Auto-generated catch block
	    	System.out.println("in handelActivityReport pdf NOT generated ");
			e.printStackTrace();
		}*/
	    catch (Exception e) {
			// TODO: handle exception
		}

	}
	public static void handelExecutionReport(ArrayList<Object> res) {
		/**
		 * create activity report using PDFGenerator
		 */
		    try {
				PDFGenerator.createExecutionReport("/" ,res.get(1).toString() , res.get(2).toString() , res.get(3).toString() , res.get(4).toString());
			} catch (DocumentException | IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	public static void handelDelaysReport(ArrayList<Object> res) {
		/**
		 * create activity report using PDFGenerator
		 */
		    try {
				PDFGenerator.createDelaysReport("/" ,res.get(1).toString() , res.get(2).toString() , res.get(3).toString() , res.get(4).toString(), res.get(5).toString(), res.get(6).toString(), res.get(7).toString(), 
						res.get(8).toString() , res.get(9).toString() , res.get(10).toString() , res.get(11).toString() , res.get(12).toString() , res.get(13).toString() , res.get(14).toString());
			} catch (DocumentException | IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	public static void openReport(ArrayList<Object> res){
		ArrayList<Object> message=new ArrayList<Object>();
		String date= res.get(2).toString();
		message.add("getReport");
		message.add(date);
		AcademicFrame.myclient.sendMessageToServer(message);
	}
	@Override
	public void display(Object message) {
		// TODO Auto-generated method stub
	}
	
}
